class Solution {
public:
    int maxOperations(vector<int>& nums, int k) {
        unordered_map<int,int> hash;
        int ret=0;
        for(auto& e:nums)
        {
            hash[e]++;
        }
        for(auto &e:hash)
        {
            if(e.first<k)
            {
                auto iter=hash.find(k-e.first);
                if(iter!=hash.end())
                {
                    if(e.first!=iter->first)
                    {
                        ret+=min(e.second,iter->second);
                        hash.erase(iter);
                    }
                    else
                        ret+=e.second/2;
                }
            }
        }
        return ret;
    }
};